package com.liuceng.peatio.service

import com.liuceng.BaseSpec
import com.liuceng.peatio.model.FrontCampaign
import com.liuceng.peatio.utils.RedisUtils
import org.springframework.beans.factory.annotation.Autowired
import redis.clients.jedis.Jedis
import redis.clients.jedis.JedisPool

/**
 * Created by liyuhang on 2016-13-11.
 */
class SelfOperationServiceSpec extends BaseSpec {
    @Autowired
    JedisPool jedisPool
    Jedis jedis

    def setup() {
        jedis = jedisPool.getResource()
        jedis.flushDB()
    }

    def "test .updateSelfOperationBudgetAndBid"() {
        given:
        FrontCampaign campaign = new FrontCampaign(id: 1, memberId: 1, campaignType: 1, dayBudget: new BigDecimal(1000.24), adOffer: new BigDecimal(1.5))
        SelfOperationService service = new SelfOperationService(jedisPool: jedisPool)
        String key = RedisUtils.buildMemberBudgetAndBidKey(campaign.getMemberId(), campaign.getCampaignType())

        when:
        service.updateSelfOperationBudgetAndBid(campaign)

        then:
        jedis.get(key) == campaign.getDayBudget() + ":" + campaign.getAdOffer()
    }
}